package com.mingtu.guards.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.TaskListCommonBean;

import java.util.List;

public class ReceiveFinishTaskAdapter extends BaseMultiItemQuickAdapter<TaskListCommonBean.PageBean.ListBean, BaseViewHolder> {

    public ReceiveFinishTaskAdapter( List<TaskListCommonBean.PageBean.ListBean> data) {
        super(data);
        addItemType(1, R.layout.item_my_receive_task1);
        addItemType(2, R.layout.item_my_receive_task2);
        addItemType(3, R.layout.item_my_receive_task3);
        addItemType(4, R.layout.item_my_receive_task4);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, TaskListCommonBean.PageBean.ListBean listBean) {
        String taskName = listBean.getName();
        String memo = listBean.getMemo();
        String endTime = listBean.getCreateTime();
        String userName = listBean.getUserName();

        switch (helper.getItemViewType()) {
            case 1:
                if (!StringUtils.isEmpty(userName)) {
                    helper.setText(R.id.tv_task_people, userName);
                }
                helper.setText(R.id.tv_task_name, taskName + "巡护任务");
                String myMemo = "";
                if (memo.indexOf("|") != -1) {
                    String[] memoArray = memo.split("\\|");
                    if (memoArray.length == 1) {
                        myMemo = "巡护" + memoArray[0];
                    } else if (memoArray.length > 1) {
                        myMemo = "巡护" + memoArray[0] + "  " + "里程" + memoArray[1];
                    }

                }
                //任务内容
                helper.setText(R.id.tv_memo, myMemo);
                helper.setText(R.id.tv_end_time, endTime + "");

                break;
            case 2:
                if (!StringUtils.isEmpty(userName)) {
                    helper.setText(R.id.tv_task_people, userName);
                }
                helper.setText(R.id.tv_task_name, taskName + "");
                helper.setText(R.id.tv_create_time, memo);
                helper.setText(R.id.tv_end_time, "" + endTime);
                break;

            case 3:
                if (!StringUtils.isEmpty(userName)) {
                    helper.setText(R.id.tv_task_people, userName);
                }
                helper.setText(R.id.tv_task_name, memo + "");
                helper.setText(R.id.tv_time, endTime + "");
                break;

            case 4:
                if (!StringUtils.isEmpty(userName)) {
                    helper.setText(R.id.tv_task_people, userName); //下发人员
                }
                helper.setText(R.id.tv_task_name, taskName + "");//任务名称
                helper.setText(R.id.tv_time, endTime + "");; //下发时间
                break;
        }
    }
}
